package com.jia.blog.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jia.blog.common.lang.R;
import com.jia.blog.entity.Banner;
import com.jia.blog.service.BannerService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author jiajia
 * @since 2020-12-02
 */
@RestController
@RequestMapping("/banner")
@Api(tags = "轮播图管理")
public class BannerController {

    @Autowired
    BannerService bannerService;

    @GetMapping("/list")
    public R list() {
        QueryWrapper<Banner> wrapper = new QueryWrapper<>();
        wrapper.eq("status",1);
        wrapper.orderByDesc("update_time");
        List<Banner> list = bannerService.list(wrapper);
        return R.ok().data("data",list);
    }
    @PostMapping("/save")
    public R save(@RequestBody Banner banner) {
        bannerService.save(banner);
        return R.ok();
    }
    @PutMapping("/update")
    public R update(@RequestBody Banner banner) {
        bannerService.updateById(banner);
        return R.ok();
    }

    @DeleteMapping("/delete/{id}")
    public R delete(@PathVariable("id") Long id){
        bannerService.removeById(id);
        return R.ok();
    }


}
